package com.xsz.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xsz.entity.Blog;
import com.xsz.repository.BlogRepository;
import com.xsz.util.KeyUtil;

@Service
public class BlogService {
	@Resource
	BlogRepository blogRepository;
	
	public Blog add(Blog blog) {
		blog.setId(KeyUtil.getId());
		blog.setCreateTime(new Date());
		blog.setModifyTime(new Date());
		return blogRepository.save(blog);
	}

	public Blog update(Blog blog) {
		blog.setModifyTime(new Date());
		return blogRepository.save(blog);
	}
	
	public void delete(String id) {
		blogRepository.deleteById(id);
	}
	
	public Blog selectById(String id) {
		return blogRepository.findById(id).get();
	}
	
	public Blog selectByTitle(String title) {
		return blogRepository.findByTitle(title);
	}

	public List<Blog> selectByAuthor(String author) {
		return blogRepository.findByAuthor(author);
	}
}
